﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using Business;
using Business.DataBusiness;

namespace MuaBanDT
{
    public partial class ChiTietHoaDonBan : Form
    {
        Utilities getData = new Utilities();
        public ChiTietHoaDonBan()
        {
            InitializeComponent();
        }

        private void btnThoatCTHDBan_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXoaCTHDBan_Click(object sender, EventArgs e)
        {
            this.tBoxMaChiTietHDB.Text = "";
            this.tBoxMaHDBCT.Text = "";
            this.tBoxSoIMEI.Text = "";
            this.tBoxDonGia.Text = "";
            this.cBoxMaDT.Text = "";
        }
       
        private void btnLuuCTHDBan_Click(object sender, EventArgs e)
        {
            try
            {
                ChiTietHDB a = new ChiTietHDB();
                a.MaCTHDB = getData.CreateID("ChiTietHDB","CTB");
                a.MaHDB = this.tBoxMaHDBCT.Text;
                a.MaDT = this.cBoxMaDT.Text;
                a.IMEI = this.tBoxSoIMEI.Text;
                a.DonGia = float.Parse(this.tBoxDonGia.Text);
                tBoxMaChiTietHDB.Text = a.MaCTHDB;

                if (a.Insert() == 1)
                {
                    MessageBox.Show("Lưu Thành Công", "Chi Tiết HD", MessageBoxButtons.OK);
                }
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }

        private void ChiTietHoaDonBan_Load(object sender, EventArgs e)
        {
            this.tBoxMaHDBCT.Items.AddRange(getData.GetHoaDon("HoaDonBan"));
            this.cBoxMaDT.Items.AddRange(getData.GetDanhMucMaDT("DanhMucDT"));
            btnXoaCTHDBan_Click(sender, e);
        }

        private void cBoxMaDT_SelectedIndexChanged(object sender, EventArgs e)
        {
            ThongTinGiaBan a = new ThongTinGiaBan();
            this.tBoxDonGia.Text = a.GiaBanDT(this.cBoxMaDT.Text);
        }

        private void tBoxDonGia_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsNumber(e.KeyChar))
            {
                MessageBox.Show("Bạn chỉ được nhập số", "Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                e.Handled = true;
            }
        }
    }
}
